package com.learn.ch02.pojo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

/**
 * @author DJJ_F
 * @version 1.0
 * @date 2025/02/16
 * @description 获取系统属性的方法
 */
@Component
public class MyEnvironment {
    @Autowired
    private Environment environment;
    public void testEnv() {
        // 获取当前激活的配置列表
        String[] activeProfiles = environment.getActiveProfiles();
        for (String activeProfile : activeProfiles) {
            System.out.println(activeProfile);
        }
        // 获取配置属性
        String property = environment.getProperty("myapp.name");
        System.out.println(property);
    }
}
